package com.tanhua.manage.controller;

import com.tanhua.manage.service.UserManageService_six;
import com.tanhua.manage.vo.Pager;
import com.tanhua.manage.vo.UserInfoVo_six;
import com.tanhua.manage.vo.UserPageVo_six;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 刘
 */
@Slf4j
@RestController
@RequestMapping("manage")
public class UserManageController_six {


    @Autowired
    private UserManageService_six userManageService;


    @GetMapping("users/{userID}")
    public ResponseEntity<UserInfoVo_six> userBaseInfo(@PathVariable("userID") Long userId){


        try {
            UserInfoVo_six userInfo_six = this.userManageService.queryUserInfoById(userId);
            if (null != userInfo_six){
                return ResponseEntity.ok().body(userInfo_six);
            }
        } catch (Exception e) {
            log.error("查询用户基本信息错误,用户ID为:"+userId,e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }



    @GetMapping("users")
    public ResponseEntity<Pager<UserPageVo_six>> userPager(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                           @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
                                                           @RequestParam(value = "id",required = false) Long id,
                                                           @RequestParam(value = "nickname",required = false) String nickname,
                                                           @RequestParam(value = "city",required = false) String city){

        try {
            Pager<UserPageVo_six> userPager = this.userManageService.queryPageUser(page,pageSize,id,nickname,city);
            if (null != userPager){
                return ResponseEntity.ok().body(userPager);
            }
        } catch (Exception e) {
            log.error("查询用户基本信息错误"+e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }






}
